package com.autumn.repo.boot;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.autumn.platform.core.Utils;
import com.autumn.repo.RepoService;
import com.autumn.repo.service.GitRepoService;

@Configuration
@EnableConfigurationProperties({RepoProperties.class})
public class RepoAutoConfiguration {

    private final RepoProperties properties;

    public RepoAutoConfiguration(RepoProperties properties) {
        super();
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean(RepoService.class)
    public RepoService repoService() {
        GitRepoService service = new GitRepoService();
        String root = properties.getRoot();
        if (!Utils.isBlank(root)) {
            service.setRoot(root);
        }
        return service;
    }
}
